package com.udata.server.util;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

import org.json.JSONObject;

import com.google.gson.Gson;

public class JsonBeautifyUtil {

	public static String beautifyJson(String content) {
		List<String> contentList = new ArrayList<String>();
		String result = null;
		Gson gson = new Gson();

		try {
			content = URLDecoder.decode(content, "UTF-8");
			JSONObject jsonObj = new JSONObject(content);
			JsonFormatter formatter = new JsonFormatter();
			result = formatter.format(jsonObj);
			contentList.add("Valid JSON");
			contentList.addAll(Arrays.asList(result.split("\n")));

		} catch (Exception e) {
			contentList.add("Error:" + e.getMessage() + "\"");
		}
		result = gson.toJson(contentList);
		return result;

	}
}
